# ---------- 构建阶段 ----------
FROM golang:1.23.6-bullseye AS builder

RUN apt-get update && apt-get install -y \
    build-essential \
    sqlite3 \
    libsqlite3-dev \
    ca-certificates

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download

COPY . .

RUN CGO_ENABLED=1 go build -o ug-tool .

# ---------- 运行阶段 ----------
FROM debian:bullseye-slim

# 安装 SQLite 和根证书
RUN apt-get update && apt-get install -y \
    sqlite3 \
    libsqlite3-0 \
    ca-certificates && \
    update-ca-certificates && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY --from=builder /app/ug-tool .

CMD ["./ug-tool"]